home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / DATAB.C < prev    next >
C/C++ Source or Header  |  1993-08-24  |  26KB  |  845 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*   databases and their functions   */
  11. /*                                   */
  12. /*        Zortech C/C++ 3.0 r4       */
  13. /*          MICROSOFT C 6.00         */
  14. /*          Visual C/C++ 1.0         */
  15. /*           QuickC/WIN 1.0          */
  16. /*             ULTRIX cc             */
  17. /*              GNU gcc              */
  18. /*                                   */
  19. /*   (include here compilers that    */
  20. /*   compiled GEPASI successfully)   */
  21. /*                                   */
  22. /*************************************/
  23.  
  24.  
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28.  
  29. #ifdef _ZTC
  30. #define MEM_DEBUG 1
  31. #include "mem.h"
  32. #else
  33. #define mem_malloc malloc
  34. #define mem_free free
  35. #define mem_realloc realloc
  36. #endif
  37.  
  38. #include "globals.h"
  39. #include "globvar.h"
  40. #include "lsoda.h"
  41. #include "strtbl.h"
  42. #include "heapchk.h"
  43.  
  44. /* structure holding information relative to kinetic mechanisms */
  45.  
  46. struct kint {
  47.                 unsigned char nsub;             /* number ofsubstrates  */
  48.                 unsigned char npro;             /* number of products   */
  49.                 unsigned char nmodf;    /* number of modifiers  */
  50.                 unsigned char revers;   /* reversability                */
  51.                 unsigned char nconst;   /* number of kin. const.*/
  52.                 char *descr;                    /* title                                */
  53.                 char *constnam;                 /* kin. constant names  */
  54.             };
  55.  
  56. /* structures for user-defined rate equations                                   */
  57.  
  58. struct nodet{
  59.          char item;
  60.          unsigned char val;
  61.          unsigned char left;
  62.          unsigned char right;
  63.         } ;
  64.  
  65. struct treet{
  66.          struct nodet node[256];
  67.          char id[64][10];
  68.          float constant[32];
  69.          int nnode,
  70.          nnum,
  71.          nid,
  72.          nsub,
  73.          npro,
  74.          nmodf,
  75.          nconst,
  76.          revers;
  77.          char descr[64];
  78.         } ;
  79.  
  80. /* structure holding simulation options                                                 */
  81.  
  82. struct opt {
  83.         int        dyn;
  84.         long    pfo;
  85.         double    endtime;
  86.         double    reltol;
  87.         double    abstol;
  88.         double    hrcz;
  89.         int        adams;
  90.         int        bdf;
  91.         int        ss;
  92.         int        debug;
  93.         int        txt;
  94.         int        structan;
  95.         int        staban;
  96.         int        stdela;
  97.         int        nonela;
  98.         int        stdcc;
  99.         int        noncc;
  100.         int        dat;
  101.         char    datname[PWIDTH];
  102.         int        datsep;
  103.         int        datwidth;
  104.         int        dattit;
  105.         int        datmca;
  106.         int        datss;
  107.         int        append;
  108.         int        quotes;
  109.         char    timeu[32];
  110.         char    concu[32];
  111.         int        scan;
  112.         int        scandens;
  113.         int        scanlog;
  114.        };
  115.  
  116. struct sp{
  117.           PDBL var;
  118.           double low;
  119.           double high;
  120.           double ampl;
  121.           int dens;
  122.           int log;
  123.           PDBL linkedto;
  124.           double factor;
  125.           int operation;
  126.          };
  127.  
  128. PDBL    params[MAX_STEP];                                                       /* ptr to parameters for each rate eq.  */
  129. int     *eff[MAX_STEP];                                                         /* ptr to parameters for each rate eq.  */
  130. unsigned char    revers[MAX_STEP];                                       /* 1 if reaction is reversible                  */
  131. struct  opt options;                                                            /* structure with simulation options    */
  132. struct  kint *ktype;                                                            /* ptr array of kinetic types & proprt  */
  133. struct  sp *sparam;                                                                     /* ptr array with parameters to scan    */
  134. PDBL    *scanpar;                                                                       /* ptrs to all possbl.params 4 scanning */
  135. PDBL    *outpel;                                                                        /* ptrs to all possbl. values for output*/
  136. PDBL    *poutelem;                                                                        /* ptrs to values for actual dat output */
  137. char    *outtit;                                                                        /* pointer to buffer with column titles */
  138. char    *treestr;                                                                       /* pointer to buffer with constant names*/
  139. char    *treeptr;                                                                       /* pointer to buffer with constant names*/
  140. int     *scindex;                                                                       /* ptr to base of array with idx to scan*/
  141. int     *lindex;                                                                        /* ptr to base of array with idx 2 links*/
  142. int     nscanpar;                                   /* number of scanning elements                      */
  143. int     noutpel;                                    /* number of output elements                        */
  144. int     totscan;                                    /* number of selected scanning params       */
  145. int     nlinks;                                                                         /* number of linked parameters                  */
  146. int     nudf;                                                                           /* number of user-def functions                 */
  147. int     nrateq;                                                                         /* number of total rate equations               */
  148. int     totsel;                                     /* number of selected output elements       */
  149. int     kfl[MAX_STEP];                                                          /* flags for kinetic types                              */
  150. unsigned int sizespar;
  151. unsigned int sizeparam;
  152. unsigned int sizeeff;
  153. unsigned int sizeoutp;
  154. unsigned int sizetr;
  155. struct  treet *tree;                                                            /* function tree for rate equations             */
  156. struct  treet tr;                                                                       /* tree for the input                                   */
  157.  
  158. /* main point for memory block allocation               */
  159. int MemAlloc( void )
  160. {
  161.  int i;
  162.  
  163.  
  164.  sizeparam = sizeof( double );
  165.  params[0] = (double *) mem_malloc( sizeparam );
  166.  if( params[0] == NULL ) return -1;
  167.  /* make the other params[i] point to NULL                                                                */
  168.  for( i=1; i<MAX_STEP; i++ ) params[i] = NULL;
  169.  
  170.  sizeeff = 1;
  171.  eff[0] = (int *) mem_malloc( sizeeff * sizeof( int ) );
  172.  if( eff[0] == NULL )
  173.  {
  174.   mem_free( params[0] );
  175.   return -1;
  176.  }
  177.  /* make the other eff[i] point to NULL                                                                   */
  178.  for( i=1; i<MAX_STEP; i++ ) eff[i] = NULL;
  179.  
  180.  /* allocate space for the MAX_TYPE descriptors of kinetic types    */
  181.  ktype = (struct kint *) mem_malloc( MAX_TYP * sizeof( struct kint ) );
  182.  if( ktype == NULL )
  183.  {
  184.   mem_free( params[0] );
  185.   mem_free( eff[0] );
  186.   return -1;
  187.  }
  188.  
  189.  sizeoutp = 4 * sizeof( PDBL );
  190.  outpel = (PDBL *) mem_malloc( sizeoutp );
  191.  if( outpel == NULL )
  192.  {
  193.   mem_free( ktype );
  194.   mem_free( params[0] );
  195.   mem_free( eff[0] );
  196.   return -1;
  197.  }
  198.  
  199.  poutelem = (PDBL *) mem_malloc( sizeof(PDBL) );
  200.  if( poutelem == NULL )
  201.  {
  202.   mem_free( outpel );
  203.   mem_free( ktype );
  204.   mem_free( params[0] );
  205.   mem_free( eff[0] );
  206.   return -1;
  207.  }
  208.  
  209.  loop = ( unsigned char (*)[MAX_STEP][MAX_MET] ) mem_malloc( MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  210.  if( loop == NULL )
  211.  {
  212.   mem_free( poutelem );
  213.   mem_free( outpel );
  214.   mem_free( ktype );
  215.   mem_free( params[0] );
  216.   mem_free( eff[0] );
  217.   return -1;
  218.  }
  219.  
  220.  rstr = ( int (*)[MAX_STEP][MAX_MOL] ) mem_malloc( MAX_STEP * MAX_MOL * sizeof( int ) );
  221.  if( rstr == NULL )
  222.  {
  223.   mem_free( loop );
  224.   mem_free( poutelem );
  225.   mem_free( outpel );
  226.   mem_free( ktype );
  227.   mem_free( params[0] );
  228.   mem_free( eff[0] );
  229.   return -1;
  230.  }
  231.  
  232.  outtit = ( char * ) mem_malloc( 25 * sizeof( char ) );
  233.  if( outtit == NULL )
  234.  {
  235.   mem_free( rstr );
  236.   mem_free( loop );
  237.   mem_free( poutelem );
  238.   mem_free( outpel );
  239.